#include "Vector2.h"
#include <math.h>
#include <iostream>
using namespace std;

const Vector2 Vector2::ZERO = Vector2(0,0);

Vector2::Vector2(): x(0), y(0) {}

Vector2::Vector2(float inx, float iny): x(inx), y(iny) {}

float Vector2::getMagnitude(){
	return (sqrt(x*x + y*y));
}

void Vector2::normalize(){
	float mag = getMagnitude();
	if (mag == 0){
		return;
	}
	x /= mag;
	y /= mag;
}

//Vector2 Vector2::crossProduct(const Vector2& v) const{
//	return Vector2((y * v.z) - (z * v.y),
//				   -((x*v.z) - (z*v.x)),
//				   (x * v.y) - (y * v.x));
//}

Vector2 Vector2::operator-(){
	return Vector2(-x,-y);
}

Vector2 Vector2::operator-(const Vector2 &v) const{
	return Vector2(x - v.x, y - v.y);
}

Vector2 Vector2::operator+(const Vector2& v) const{
	return Vector2(x + v.x, y + v.y);
}

Vector2 Vector2::operator/(const float d) const{
	return Vector2(x / d, y / d);
}

Vector2 Vector2::operator*(const float m) const{
	return Vector2(x * m, y * m);
}

float Vector2::operator*(const Vector2& v) const{
	return (x * v.x) + (y * v.y);
}

float& Vector2::operator[] (unsigned i){
	switch(i){
		case 0:
			return x;
		case 1:
			return y;
		default:
			throw -1;
	}
}

bool Vector2::operator==(const Vector2& other) const
{
	return ( (x == other.x) && (y == other.y) );
}